package com.ld.security.server.user.modules.ups.vo;

import com.ld.security.common.core.base.SuperVo;
import com.ld.security.common.mybatis.anno.QueryKey;
import com.ld.security.common.mybatis.anno.SaveKey;
import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.common.mybatis.anno.SqlKeys;
import com.ld.security.common.mybatis.constant.SqlCondition;
import com.ld.security.server.user.modules.ups.constant.UpsKeywordConstant;
import com.ld.security.server.user.modules.ups.entity.UpsKeywordEntity;
import com.ld.security.server.user.modules.ups.entity.UpsUserLikeEntity;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class KeywordLikeVo implements SuperVo {

    private String upsUserId;

    private UpsKeywordConstant.wtType wtType = UpsKeywordConstant.wtType.content_type;

    /**
     * 经常浏览类型关键字
     */
    @QueryKey
    @SqlKeys(value = {
            @SqlKey(name = "upsUserId",valueField = "upsUserId"),
            @SqlKey(name = "wtType",valueField = "wtType"),
    })
    private List<UpsKeywordEntity> likeKeyList;


    @QueryKey(groupKey = "upsUserId")
    @SqlKey(name = "keyword",value = SqlCondition.in,valueField = "likeKeyList.keyword")
    private Map<String,List<UpsKeywordEntity>> likeUserMap;


    @SaveKey
    @QueryKey
    @SqlKey(name = "upsUserId",valueField = "upsUserId")
    private List<UpsUserLikeEntity> userLikeList;

    /**
     * 添加一个喜爱用户
     * @return
     */
    public KeywordLikeVo addLikeUser(UpsUserLikeEntity key){

        for (UpsUserLikeEntity user : userLikeList) {
            if(user.getWtType() == key.getWtType()){
                if(user.getUpsUserLikeId().equals(key.getUpsUserLikeId())){
                    user.setWt(user.getWt()+key.getWtType().wt);
                    return this;
                }
            }
        }

        //初始化权重
        key.setWt(key.getWtType().wt);
        userLikeList.add(key);
        return this;
    }

}
